<template>
  <div>
    <el-form :inline="true" style="padding: 10px 0" @submit.native.prevent>
      <el-form-item label="待短化的长网址">
        <el-input clearable v-model="longUrl" placeholder="长网址"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="generateDwz">生成短网址</el-button>
      </el-form-item>
      <h1 v-if="shortUrl" style="color: #fff;">短网址为: <a :href="shortUrl" style="color: #900712;">{{shortUrl}}</a></h1>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "dwzGenerate",
  data() {
    return {
      shortUrl: null,
      longUrl: null
    };
  },

  methods: {
    generateDwz: function() {
      this.$api.dwz.generateDwz(this.longUrl).then(res => {
        if (!res) {
          return;
        }

        this.shortUrl = res.body.shortUrl;
      });
    }
  }
};
</script>
